import { create } from 'zustand'
import defaultOptions from '@/components/ThemeSetter/defaultOptions'
import storage from '@/utils/storage'
const defineThemeStore = create<ThemeSetter.ThemeType>((set, get) => ({
  label: 'light',
  borderRadius: 3,
  colorPrimary: defaultOptions[0]['colorPrimary'],
  setLabel: (value: string) => {
    set({
      label: value
    })
    storage.set('theme', value)
  },
  setTheme: (themeValue: string) => {
    set({
      colorPrimary: themeValue
    })
    storage.set('colorPrimary', themeValue)
  },
  init: () => {
    // console.log(storage.get('theme'))
    const themeLabelList = ['light', 'dark']
    if (storage.get('theme')) {
      if (themeLabelList.indexOf(storage.get('theme')) > -1) {
        set({
          label: storage.get('theme'),
          colorPrimary: storage.get('colorPrimary')
        })
      }
    }
  }
}))
export default defineThemeStore
